#include <gnome.h>

#include "support.h"
#include "interface.h"
#include "callbacks.h"

#include "preamble.h"

static UWORD input_alabel,input_length; /* is ALABEL & value of NLABEL */

static void stringCallback(gchar *string,gpointer data)
{
  GtkWidget *textScreen=lookup_widget(GTK_WIDGET(appMain),"textScreen");
  GdkColor colorInput={0,0xffff,0,0}; /* red color */
  int i;
  char ch;

  if (string!=NULL&&strlen(string)!=0)
    for (i=0;i<input_length&&string[i]!='\0';i++)
      memoryWrite(input_alabel+i,(WORD)string[i]);

  for (i=0;i<input_length&&(ch=memoryRead(input_alabel+i))!='\0';i++)
    gtk_text_insert (GTK_TEXT (textScreen), NULL, &colorInput, NULL, &ch, 1);

  gtk_main_quit();
}

void input(UWORD alabel,UWORD nlabel)
{
  GtkWidget *dialog;
  gchar *inputInfo;

  input_alabel=alabel;
  input_length=memoryRead(nlabel);
  inputInfo=g_strdup_printf(_("Input %d character(s): "),input_length);
  dialog=gnome_request_string_dialog_parented(inputInfo,
					      (GnomeStringCallback)stringCallback,
					      NULL,
					      GTK_WINDOW(appMain));
  g_free(inputInfo);
  gtk_window_set_modal(GTK_WINDOW(dialog),FALSE);

  gtk_main();
}

void output(UWORD alabel,UWORD nlabel)
{
  gint i,length=memoryRead(nlabel);

  for (i=0;i<length;i++)	/* output a string */
    display("%c",(char)memoryRead(alabel+i)); 
}
